package com.belarus.kamianiec.photo.photoSite.web.ctrl;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.belarus.kamianiec.photo.photoSite.domain.Services;
import com.belarus.kamianiec.photo.photoSite.service.ServicesService;

//@Controller
public class ServicesController {

	private ServicesService servicesService;

	@RequestMapping("/services")
	public String listServices(Map<String, Object> map) {
		map.put("services", new Services());
		map.put("servicesList", servicesService.listService());
		return "services";
	}

	@RequestMapping(value = "/servicesadd", method = RequestMethod.POST)
	public String addService(@ModelAttribute("services") Services services, BindingResult result) {
		servicesService.addService(services);
		return "redirect:/auto";
	}

	@RequestMapping("/servicesdel/{servicesId}")
	public String deleteService(@PathVariable("servicesId") Integer autoId) {
		servicesService.removeService(autoId);
		return "redirect:/services";
	}

	public ServicesService getServicesService() {
		return servicesService;
	}

	@Autowired
	public void setServicesService(ServicesService servicesService) {
		this.servicesService = servicesService;
	}
}
